<template>
  <div>
    <div class="officeRankTop" v-for="item in officeRankList" :key="item.id">
      <div style="position:relative" @click="goSongDetail(item.id)">
        <div class="songCount">
          <i class="iconfont icon24gl-play"></i>
          <span>{{CalcPlayCount(item.playCount)}}</span>
        </div>
        <img :src="item.coverImgUrl" alt width="200" height="200" />

        <div class="songPlay">
          <i class="iconfont iconbofang"></i>
        </div>
      </div>
      <div class="officeList">
        <office-list :id="item.id"></office-list>
      </div>
    </div>
    <div class="officeRankFooter">
      <div class="officeRankFooterBody" v-for="item in officeRankOtherList" :key="item.id" @click="goSongDetail(item.id)">
        <div class="songCount">
          <i class="iconfont icon24gl-play"></i>
          <span>{{CalcPlayCount(item.playCount)}}</span>
        </div>
        <img :src="item.coverImgUrl" alt width="200" height="200" />

        <div class="songPlay">
          <i class="iconfont iconbofang"></i>
        </div>
        <div>{{item.name}}</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import axios from '@/http'
import officeList from './officeList.vue'
onMounted(async () => {
  getOfficeRankList()
})
const CalcPlayCount = computed(() => count => {
  return count > 10000 ? Math.ceil(count / 10000) + '万' : count
})
const router = useRouter()
const officeRankList = ref([])
const officeRankOtherList = ref([])
const goSongDetail = id => {
  router.push('/home/playList/' + id)
}
const getOfficeRankList = () => {
  axios.get('/toplist/detail').then(res => {
    console.log(res)
    officeRankList.value = res.data.list.filter(item => item.tracks.length)
    officeRankOtherList.value = res.data.list.filter(item => !item.tracks.length)
  })
}
</script>

<style scoped lang="scss">
.officeRankTop {
  display: flex;
  position: relative;
  margin: 0px 0 48px 0;
  img {
    border-radius: 4px;
    &:hover {
      cursor: pointer;
    }
    &:hover + .songPlay {
      opacity: 1;
      cursor: pointer;
    }
  }
  .songCount {
    position: absolute;
    font-size: 12px;
    font-weight: bolder;
    color: #fff;
    right: 10px;
    top: 3px;
    .iconfont {
      font-size: 12px;
      margin-right: 3px;
    }
  }
  .songPlay {
    width: 50px;
    height: 50px;
    background-color: rgba(255, 255, 255, 0.8);
    position: absolute;
    border-radius: 50%;
    overflow: hidden;
    bottom: 0px;
    top: 0px;
    right: 0px;
    left: 0;
    margin: auto;
    transition: opacity 0.15s;
    opacity: 0;
    &:hover {
      opacity: 1;
      cursor: pointer;
    }
    &::after {
      position: absolute;
      content: '';
      filter: blur(30px);
      background-attachment: scroll;
      width: 30px;
      background-size: 150px 150px;
      background-repeat: no-repeat;
      background-position: -110px -104px;
      left: 0;
      background-color: #b3b3b3;
      height: 30px;
    }
    .iconfont {
      font-size: 24px;
      position: absolute;
      color: red;
      left: 16px;
      top: 13px;
      right: 0;
      bottom: 0;
      margin: auto;
    }
  }
  .officeList {
    flex: 1;
  }
}
.officeRankFooter {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .officeRankFooterBody {
    position: relative;
    margin: 16px 0;
    color: #b3b3b3;
    font-size: 14px;
    font-weight: bold;
    img {
      border-radius: 4px;
      &:hover {
        cursor: pointer;
      }
      &:hover + .songPlay {
        opacity: 1;
        cursor: pointer;
      }
    }
    .songCount {
      position: absolute;
      font-size: 12px;
      font-weight: bolder;
      color: #fff;
      right: 10px;
      top: 3px;
      .iconfont {
        font-size: 12px;
        margin-right: 3px;
      }
    }
    .songPlay {
      width: 50px;
      height: 50px;
      background-color: rgba(255, 255, 255, 0.8);
      position: absolute;
      border-radius: 50%;
      overflow: hidden;
      bottom: 100px;
      right: 0px;
      left: 0;
      margin: auto;
      transition: opacity 0.15s;
      opacity: 0;
      &:hover {
        opacity: 1;
        cursor: pointer;
      }
      &::after {
        position: absolute;
        content: '';
        filter: blur(30px);
        background-attachment: scroll;
        width: 30px;
        background-size: 150px 150px;
        background-repeat: no-repeat;
        background-position: -110px -104px;
        left: 0;
        background-color: #b3b3b3;
        height: 30px;
      }
      .iconfont {
        font-size: 24px;
        position: absolute;
        color: red;
        left: 16px;
        top: 13px;
        right: 0;
        bottom: 0;
        margin: auto;
      }
    }
  }
}
</style>